<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.fileupload.FileItem" %>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<title>업로드 정보</title>
<%
	boolean isMultipart = ServletFileUpload.isMultipartContent(request);
	if(isMultipart){
		DiskFileItemFactory factory = new DiskFileItemFactory();		
		ServletFileUpload upload = new ServletFileUpload(factory);
		List<FileItem> items = upload.parseRequest(request);
		
		for(FileItem item:items){
			if(item.isFormField()){
				String name = item.getFieldName();
				String value = item.getString("utf-8");
%>
				요청 파라미터: <%=name%> = <%=value%><br>	
<%				
			}else{
				String name = item.getFieldName();
				String fileName = item.getName();
				String contentType = item.getContentType();
				long sizeInBytes = item.getSize();
				
				//업로드 파일 저장
				item.write(new File("c:/save/"+fileName));
				
%>
				파일: <%= name %>,<%= fileName %>(<%= contentType %>),<%= sizeInBytes %><br>
<%								
			}
		}
	}else{
%>
		multipart/form 요청이 아님.
<%
	}
%>		
		
		
		